package com.cagtwitter.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cagtwitter.services.WebDataServices;

/**
 * Servlet implementation class Tweets
 */
@WebServlet("/Tweets")
public class Tweets extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Tweets() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    // Parameters = query,screen_name,count,page
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String query = request.getParameter("query");
		
		//request.setCharacterEncoding("UTF-8");
		
		
		String screen_name = request.getParameter("screen_name");
		
		if(query.equals("getUserTweets")){
			WebDataServices wds = new WebDataServices();
			Properties properties = new Properties();
			
			properties.setProperty("count",request.getParameter("count"));
			properties.setProperty("page",request.getParameter("page"));
			properties.setProperty("include_rts","true");
			//properties.setProperty("trim_user","true");
			
			PrintWriter out = response.getWriter();
			
			
		    out.println(wds.getUserTimeline(screen_name,properties));
		    out.close();
		}

		else if(query.equals("getTweetsAboutUser")){
			WebDataServices wds = new WebDataServices();
			PrintWriter out = response.getWriter();
			
			out.println(wds.getTweetsAboutUser(screen_name,request.getParameter("page_num")));
			out.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		
	}

}
